package com.gitee.shigen.es.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.gitee.shigen.es.mapper.IndexObjectMapper;
import com.gitee.shigen.es.service.IndexObjectService;
import com.gitee.shigen.es.vo.IndexObject;

import cn.easyes.core.biz.PageInfo;
import cn.easyes.core.conditions.LambdaEsQueryWrapper;
import cn.hutool.core.util.StrUtil;

/**
 * @author shigenfu
 * @date 2023/4/30 10:32 下午
 */
@Service
public class IndexServiceImpl implements IndexObjectService {

    @Resource
    private IndexObjectMapper indexObjectMapper;

    @Override
    public int insertBatch(List<IndexObject> indexObjects) {
        return indexObjectMapper.insertBatch(indexObjects);
    }

    @Override
    public int deleteById(Long id) {
        return indexObjectMapper.deleteById(id);

    }

    @Override
    public int update(IndexObject indexObject) {
        return indexObjectMapper.updateById(indexObject);
    }

    @Override
    public PageInfo<IndexObject> page(String keyword, Integer pageNum, Integer pageSize) {
        LambdaEsQueryWrapper<IndexObject> queryWrapper = new LambdaEsQueryWrapper<>();
        queryWrapper.multiMatchQuery(StrUtil.isNotEmpty(keyword), keyword, IndexObject::getKeywords, IndexObject::getTitle,
            IndexObject::getDescription);
        return indexObjectMapper.pageQuery(queryWrapper, pageNum, pageSize);
    }
}
